<template>
    <div id="app">
        <router-view></router-view>
    </div>
</template>

<script>
    import {getUserCount, getCartCount} from 'network';

    export default {
        name: 'app',
        created() {
            if (this.$cookie.get('userId')) {
                this.getUser();
                this.getCart();
            }
        },
        methods: {
            getUser() {
                // res={} 给res一个默认值
                getUserCount().then((res = {}) => {
                    // console.log(res.username)
                    this.$store.dispatch('saveUserName', res.username);
                })
            },
            getCart() {
                getCartCount().then((res = 0) => {
                    this.$store.dispatch('saveCartCount', res);
                })
            }
        }
    }
</script>

<style lang="scss">
    @import 'assets/scss/base.scss';
    @import 'assets/scss/button.scss';
</style>
